package ebj.common.queue.request;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.log4j.Logger;

import com.sun.net.httpserver.HttpServer;

import ebj.common.queue.request.queue.QueryExecuteThreadPool;
import ebj.common.queue.request.service.Report;
import ebj.common.queue.request.service.TestOk;



public class MyHttpServer {
    static Logger logger = Logger.getLogger(MyHttpServer.class);
    private static int port = 9099;
    static Timer timer = null;
    
    static{
        timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {
                QueryExecuteThreadPool.initCustomerPool();
            }
        }, 100, 5000);
    }
    
    public static void main(String[] args) {
        HttpServer server = null;
        try {
            server = HttpServer.create(new InetSocketAddress(port), 0);
            server.createContext("/ok", new TestOk());
            server.createContext("/report", new Report());
            System.out.println("isInfoEnabled = " + logger.isInfoEnabled());
            System.out.println("isDebugEnabled = " + logger.isDebugEnabled());
            server.setExecutor(null); // creates a default executor
            logger.info("start server[status, getAds] at port " + String.valueOf(port));
            server.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
